WDV2221 Intro Javascript

Unit-4 Assignment - Functions Parameters & Returns

Directions:

Instructions: Define and assign the variables based upon the instructions in the script tags on this page.

Example 1

  1. Create a runtime script that will call formatRosterName().
  2. Place the script so that it will display the name in the following heading.
  3. Pass the global variables firstName and lastName into the function.

Student Name:

Example 2

  1. Create a button called "Display Name".
  2. Assign an onclick event handler to the button that will call displayName().
  3. Pass the global variables firstName and lastName into the function.
  4. Fix the function so that there is proper spacing

Example 3

  1. Create a function called displaySchool( ).
    • the function will accept one input parameter called inValue
    • the function will display the input value on the console using console.log().
  2. Call this function using a button and the onclick event handler. Pass in the schoolName variable as the parameter to the displaySchool().
    • See the Console in the Dev Tools to see function results.

Example 4

  1. Create a function called printName( ).
    • the function will accept two parameters, inFirstName and inLastName
    • concatenate the names into a single string formatted as "firstName lastName"
    • display the result string to the console using console.log()
  2. Call this function during runtime. Pass in the firstName and lastName variables as the parameters.
    • NOTE: Open the dev tools to see the function results in the Console

Example 5

  1. Create a global variable called totalSales. Assign it a value of 3435.6. It should be numeric data type.
  2. Create a function called formatCurrency().
    • the function will accept one input parameter called inNumber
    • the function will use the currency formatting discussed in this unit
    • use a 'return' statement to deliver the formatted number to where the function is called
  3. Use a runtime script to display the formatted number instead of the message in the heading shown below.

Your Total Sales:

Return to WDV 221 Homework Page